package sau.diyizu.media;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.List;

/**
 @author JYD
 @version 1.0
 @since 2020/12/15 20:13 */
public class ViewPagerAdapter extends FragmentStatePagerAdapter {

    private List<Pager> pagerList;

    @SuppressLint("WrongConstant")
    public ViewPagerAdapter(@NonNull FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return pagerList.get(position).fragment;
    }

    @Override
    public int getCount() { return 2; }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) { return pagerList.get(position).title; }

    public void setPagers(List<Pager> pagers) {
        pagerList = pagers;
    }

    public static class Pager {
        public String title;
        public Fragment fragment;

        public Pager(@NonNull String title, @NonNull Fragment fragment) {
            this.title = title;
            this.fragment = fragment;
        }
    }
}